/**
 * ValidateUtil.java
 * com.sftz.framework.util
 * Copyright (c) 2018, 北京科技有限公司版权所有.
*/

package com.sftz.framework.util;

import java.util.regex.Pattern;

/**
 * 用户输入信息验证工具
 * <p>
 *
 * @author   朱晓川
 * @Date	 2018年6月15日 	 
 */
public class ValidateUtil {

	/**
	 * 130到9
	 * 145或147
	 * 150到3,5到9
	 * 170,171,173,176,177,178
	 * 180,5到9
	 */
	public static String REGEX_TEL = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";

	private ValidateUtil() {
	}

	/**
	 * 验证手机号
	 */
	public static boolean validateTel(String tel) {
		return Pattern.matches(REGEX_TEL, tel);
	}

	/**
	 * 验证指定长度的数字
	 */
	public static boolean validateNumber(String num, int minLength, int maxLength) {
		String numRegex = "\\d{" + minLength + "," + maxLength + "}";
		return Pattern.matches(numRegex, num);
	}

	/**
	 * 验证指定长度的文本
	 */
	public static boolean validateText(String text, int minLength, int maxLength) {
		String numRegex = ".*{" + minLength + "," + maxLength + "}";
		return Pattern.matches(numRegex, text);
	}

}
